package com.ilink.teacherservice.controller.videoTranscription;


import com.ilink.ilinkcommon.domain.R;
import com.ilink.ilinkcommon.domain.PO.studyservice.FileTranscriptionTaskResponse;
import com.ilink.ilinkcommon.log.method.MethodLog;
import com.ilink.teacherservice.mapper.FileTranscriptionMapper;
import com.ilink.teacherservice.service.videoTranscription.FileTranscriptionService;
import com.ilink.teacherservice.utils.videoTranscription.FileTranscriptionParameters;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fileTrans")
public class FileTranscriptionController {

    @Autowired
    private FileTranscriptionService fileTransService;

    @Autowired
    private FileTranscriptionMapper fileTransMapper;

    @MethodLog
    @PostMapping("/createTask")
    public R test(@RequestBody FileTranscriptionParameters parameters){
        String fileUrl = parameters.getFile_url();
        boolean diarization_enabled = parameters.isDiarization_enabled();
        int speaker_count = parameters.getSpeaker_count();
        boolean translation_enabled = parameters.isTranslation_enabled();
        List<String> language= parameters.getLanguage();

        FileTranscriptionTaskResponse result = fileTransService.createFileTransTask(
                                                                    fileUrl,
                                                                    diarization_enabled,
                                                                    speaker_count,translation_enabled,
                                                                    language);
        return R.ok(result);
    }

    @MethodLog
    @GetMapping("/getInfo")
    public R getResult(@RequestParam String taskId, @RequestParam String sourcePath){
        FileTranscriptionTaskResponse result = fileTransService.getFileTransInfo (taskId, sourcePath);
        if(result != null){
            return R.ok(result);
        }else{
            return R.error("文件未找到"+taskId);
        }
    }

}